package com.example.peibei.ui.activity;

import android.view.View;
import android.widget.ImageView;

import com.dingtao.common.bean.User;
import com.dingtao.common.core.DataCall;
import com.dingtao.common.core.WDActivity;
import com.dingtao.common.core.exception.ApiException;
import com.dingtao.common.util.SPUtils;
import com.example.peibei.R;
import com.example.peibei.base.SpConstant;
import com.example.peibei.bean.SpUserInfoCall;
import com.example.peibei.service.presenter.UserInfoPresenter;

import butterknife.BindView;
import butterknife.OnClick;

public class AuthCenterActivity extends WDActivity {
    @BindView(R.id.iv_sm)
    ImageView iv_sm;
    @BindView(R.id.iv_wsm)
    ImageView iv_wsm;
    @BindView(R.id.iv_sj)
    ImageView iv_sj;
    @BindView(R.id.iv_wsj)
    ImageView iv_wsj;

    private SPUtils spUtils;
    private String token;
    private boolean identityBool;
    private UserInfoPresenter userInfoPresenter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_auth_center;
    }

    @Override
    protected void initView() {
        spUtils = new SPUtils(AuthCenterActivity.this, SpConstant.USER_TOKEN);
        userInfoPresenter = new UserInfoPresenter(new UserInfoCall());
    }

    @Override
    protected void onResume() {
        super.onResume();
        token = spUtils.getString(SpConstant.USER_TOKEN);
        userInfoPresenter.reqeust("Bearer " + token);
    }

    @OnClick(R.id.iv_back)
    public void back(){
        finish();
    }

    @OnClick(R.id.rl_auth_real)
    public void authReal(){

    }

    @OnClick(R.id.rl_auth_sm)
    public void authSm(){
        intent(RealNameActivity.class);
    }

    @OnClick(R.id.rl_auth_phone)
    public void authPhone(){
        intent(ChangePhoneActivity.class);
    }

    class UserInfoCall extends SpUserInfoCall {

        @Override
        public void success(User data, Object... args) {
            super.success(data,args);
            spUtils.putLong(SpConstant.USER_MID, data.getId());
            identityBool = data.isIdentityBool();
            if (identityBool) {
                iv_sm.setVisibility(View.VISIBLE);
                iv_wsm.setVisibility(View.GONE);
            } else {
                iv_sm.setVisibility(View.GONE);
                iv_wsm.setVisibility(View.VISIBLE);
            }
            if (data.isMobileBool()){
                iv_sj.setVisibility(View.VISIBLE);
                iv_wsj.setVisibility(View.GONE);
            }else{
                iv_sj.setVisibility(View.GONE);
                iv_wsj.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void fail(ApiException e, Object... args) {

        }
    }

    @Override
    protected void destoryData() {

    }
}
